package com.yangquan.ayuan.creatThread;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class CallableExample implements Callable<String> {
    @Override
    public String call() throws Exception {
        return "执行结果: " + true;
    }
}

class App_3 {
    public static void main(String[] args) throws Exception {
        // 1. 创建一个带有返回值的任务对象
        CallableExample callableExample = new CallableExample();
        // 2. 通过 Future类 结合 Callable类来创建带有返回值的线程
        FutureTask<String> futureTask = new FutureTask<>(callableExample);
        // 3. 将 futureTask 对象传递给 Thread类
        Thread thread = new Thread(futureTask);
        thread.start();

        // 4. 等待子线程执行结束
        thread.join();
        // 5. 获取子线程执行结果
        String result = futureTask.get();
        System.out.println(result);
    }
}